
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.ArrayList,
                 com.scalar.chiptrack.utils.ConfigManager,
                 com.scalar.chiptrack.users.Functionality,
                 com.scalar.chiptrack.users.User,
                 com.scalar.chiptrack.sales.forms.AddNewContactPersonForm"%>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<chiptrack:checkLogon sourcePage="/addNewContactPerson.do"/>

<html:html locale="true">

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type=text/css rel=stylesheet>

<script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js">
</script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js">
</script>

<script language='javascript'>
var temperror= '';
function save()
{
    var errors = '';
    var contactperson = document.addNewContactPersonForm.newContactPerson.value;
	var email         = document.addNewContactPersonForm["email"];
    if( contactperson == '' || contactperson.trim().length == 0)
    {
	     errors = errors + "<li> Please enter Contact Person name ";
    }
    //added by varma 29 jul 2004 to restrict double quote in Contact Person name
    if( contactperson.indexOf('"') >= 0 )
    {
          errors = errors + "<li> Please enter a Valid Contact Person Name";
          document.addNewContactPersonForm.newContactPerson.select();
          document.addNewContactPersonForm.newContactPerson.focus();

    }

    if( email.value != '' )
	{
        if( !isValidEMailId( email ) )
        {
            errors=errors+ '<br>'+'<li> Please enter a valid email address';
            email.select();
            email.focus();
        }
	}

    if( errors != '' )
    {
        var inf = document.getElementById("infoMessagesId");
        inf.innerHTML = '';
        var err = document.getElementById("errorMessagesId");
        err.innerHTML = '';

        var pa=document.getElementById("errors");
        pa.innerHTML = errors;
        return ;
    }

    if( temperror != '' )
    {
        return ;
    }

   var customerId = window.opener.document.customerForm['customer.customerId'].value;
   var contactPersonValue = document.addNewContactPersonForm.contactPersonValue.value;
   var shippingAddressId = document.addNewContactPersonForm.customerId.value;
   var action = '<%=request.getParameter("action")%>';
   if( action == 'editContactPerson' )
   {
        action = 'saveEditContactPerson' ;
   }
   else
   {
        action = 'insertContactPerson';
   }

    if( contactPersonValue =='Customer')
	{
		document.addNewContactPersonForm.action = '<%=chipTracContext%>/addNewContactPerson.do?action='+action+'&value='+contactPersonValue+'&customerId=' + customerId;

	}

	if( contactPersonValue =='Address')
	{

		document.addNewContactPersonForm.action = '<%=chipTracContext%>/addNewContactPerson.do?action='+action+'&value='+contactPersonValue+'&customerId=' + shippingAddressId;

	}

    document.addNewContactPersonForm.submit();
}

function reset()
{
    document.addNewContactPersonForm.reset();
}

function closeWindow(form)
{
    window.opener.document.customerForm['customer.customerNumber'].disabled=false;
    window.opener.document.customerForm.submit();
 	window.close();
}

</script>

<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY bgColor='#ffffff' leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">

<!-- from here your body starts -->
<html:form name="addNewContactPersonForm" type="com.scalar.chiptrack.sales.forms.AddNewContactPersonForm" scope="request" action='/addNewContactPerson.do?action=insertContactPerson' >
<img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20>
<center><span class="NArialW">Contact Person Details</span></center>
<img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20>
<table border="0" width="90%" align=right>
    <tr>
        <td>
            <table border="0" width="75%" cellspacing='2' cellpadding='2' >
                <tr><td colspan='4' align=right><a href="javascript:closeWindow(document.addNewContactPersonForm);" onMouseOver="window.status='Click here to close this window';return true"onmouseout="window.status='';return true"><font class='NArialL'>Close this window</font></a></td></tr>
                <tr><td colspan='4' id="infoMessagesId"><chiptrack:info styleClass='NArialL' /></td></tr>
                <tr><td colspan='4' id="errorMessagesId"><chiptrack:errors styleClass='NArialL' /></td></tr>
                <tr><td><img height=10 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif"></td></tr>
                <tr><td colspan='3' align="left" class='NArialL'><FONT id="errors" styleClass="NArialL" color='FF0000'></FONT></TD></TR>
                <tr>
                    <td width="25%" align='right' nowrap><font class="NArialL">Contact Person :<font color=red>*</font></font></td>
                    <td width="25%" ><html:text property="newContactPerson" size="20" styleClass="txfield" maxlength="50" /></td>
                </tr>
	            <tr>
                    <td width="25%" align='right'><font class="NArialL">Phone :&nbsp;&nbsp;</font></td>
                    <td width="25%" ><html:text property="phoneNumber" size="20" styleClass="txfield" maxlength="<%=ConfigManager.getProperty(ConfigManager.ADDRESS_PHONE_MAX_LENGTH)%>" onkeypress='validatePhoneNumber(this)'/></td>
                    <td width="25%" align='right' nowrap><font class="NArialL">Cell No :&nbsp;&nbsp;</font></td>
                    <td width="25%" ><html:text property="cellNumber" size="20" styleClass="txfield" maxlength="50" onkeypress='validatePhoneNumber(this)'/></td>
                </tr>
                <tr>
                    <td width="25%" align='right'><font class="NArialL">Fax :&nbsp;&nbsp;</font></td>
                    <td width="25%" ><html:text property="faxNumber" size="20" styleClass="txfield" maxlength="<%=ConfigManager.getProperty(ConfigManager.ADDRESS_FAX_MAX_LENGTH)%>" onkeypress='validatePhoneNumber(this)'/></td>
                    <td width="25%" align='right'><font class="NArialL">Email :&nbsp;&nbsp;</font></td>
                    <td width="25%" ><html:text property="email" size="20" styleClass="txfield" maxlength="50" /></td>
                </tr>
                <tr><td colspan="4" ></td></tr>
                <tr>
                    <td colspan="2" align='left' nowrap><html:checkbox property="salesAckMail" /> <FONT class='NArialL'>Receive SalesOrder Acknowledge Mails </FONT></td>
                    <td colspan="2" align='left'><html:checkbox property="shipAlerts"  /> <font class="NArialL">Receive Ship Alert Mails</font></td>
                </tr>
                <tr>
                    <td colspan="2" align='left'><html:checkbox property="proformaInvoice"  /> <FONT class='NArialL'>Receive Proforma Invoice Mails </FONT></td>
                    <td colspan="2" align='left'><html:checkbox property="packingSlip"  /> <font class="NArialL">Receive Packing Slip Mails</font></td>
                </tr>
                <tr>
                    <td colspan="2" align='left'><html:checkbox property="quoteAckMail" /> <FONT class='NArialL'>Receive Quote Acknowledge Mails </FONT></td>
                    <td colspan="2" align='left'><html:checkbox property="rmaAckMail" /> <FONT class='NArialL'>Receive RMA Acknowledge Mails </FONT></td>
                </tr>
                <%--<tr>
                    <td width="25%" align='left' colspan="2"><html:checkbox property="commerInvoice" /> <FONT class='NArialL'>Receive Commercial Invoice Mails </FONT></td>
                </tr>--%>
                <tr><td colspan="4" ></td></tr>
                <tr>
                    <td colspan='2' nowrap align='right'>
                        <chiptrack:restrictedLink functionality='<%=Functionality.CUSTOMER_DETAILS%>' action='<%=User.USER_ACTION_MODIFY%>' styleClass="leftsection" href="javascript:save()" onmouseover="window.status='Click to Save Contact Person';return true" onmouseout="window.status='';return true"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/save.gif" title="Click here to Save Contact Person"/></chiptrack:restrictedLink>
                    </td>
                    <td colspan='1' nowrap align='left'>
                        <a href="javascript:reset()" onmouseover="window.status='Click to Reset';return true;" onmouseout="window.status='';return true" title="Click here to Reset"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" width="53" height="17"></a>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td>
        <!-- DISPLAY ALL USERS STARTS HERE -->
        <%
            ArrayList contactPersons = (ArrayList) request.getAttribute( "contactPersons" );
            if( contactPersons != null && contactPersons.size() != 0 )
            {
        %>

            <table border="0" width="50%" bordercolor="#FFFFFF" align="center">
                <tr>
                    <td  align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Contact Person</font></font></td>
                    <td  align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Action</font></font></td>
                </tr>
                <logic:iterate id="ContactPerson" name="contactPersons" type="com.scalar.chiptrack.sales.ContactPerson">
                <% int bgcount = 0;%>
                <% bgcount = bgcount + 1; %>
                <tr>
                    <td nowrap align="left" <%if(bgcount%2==0){%> bgcolor='#DEE1E2' <% } else {%> bgcolor='#FFFFEE' <%}%>><font class="NArialL">
                        <bean:write name="ContactPerson" property="contactPerson" /></font>
                    </td>
                    <td nowrap  align="center" <%if(bgcount%2==0){%> bgcolor='#DEE1E2' <% } else {%> bgcolor='#FFFFEE' <%}%>>
                        <font class="NArialL">
                        <logic:equal name="ContactPerson" property="disabled" value="true">
                        <a href='<%=chipTracContext%>/addNewContactPerson.do?contactPersonstatus=disable&contactPerson=<bean:write name="ContactPerson" property="encodeContactPerson" />&customerId=<%=request.getParameter("customerId")%>&value=<%=request.getParameter("value")%>'onmouseover="window.status='Click to Disable Contact Person';return true;"onmouseout="window.status='';return true">Disable</a>
                        </logic:equal>
                        <logic:equal name="ContactPerson" property="disabled" value="false">
                        <a href='<%=chipTracContext%>/addNewContactPerson.do?contactPersonstatus=activate&contactPerson=<bean:write name="ContactPerson" property="encodeContactPerson" />&customerId=<%=request.getParameter("customerId")%>&value=<%=request.getParameter("value")%>'onmouseover="window.status='Click to Activate Contact Person';return true;"onmouseout="window.status='';return true"><font color='red'> Activate</font></a>
                        </logic:equal>
                         &nbsp;&nbsp;<a href='<%=chipTracContext%>/addNewContactPerson.do?action=editContactPerson&contactPerson=<bean:write name="ContactPerson" property="encodeContactPerson" />&customerId=<%=request.getParameter("customerId")%>&value=<%=request.getParameter("value")%>'onmouseover="window.status='Click to Edit Contact Person';return true;"onmouseout="window.status='';return true"> Edit </a>
                        </font>
                    </td>
                </tr>
                </logic:iterate>
                <tr><td class="NArialL" colspan=5><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=50></td></tr>
                <tr><td colspan=3 align=center><a href="javascript:closeWindow(document.addNewContactPersonForm);" onMouseOver="window.status='Click here to close this window';return true" onmouseout="window.status='';return true"><font class='NArialL'>Close this window</font></a></td></tr>
            </table>
	    <% } %>
        <!-- DISPLAY ALL USERS ENDS HERE -->
        </td>
    </tr>
</table>
<input type="hidden" name="customerId" value ='<%=request.getParameter("customerId")%>' >
<input type="hidden" name="contactPersonValue" value ='<%=request.getParameter("value")%>' >
 <%-- <input type="hidden" name="action" value ='<%=request.getParameter("action")%>' > --%>
</html:form>
</body>
</html:html>